package main

func main() {
	println(isValid("()"))
}

func isValid(s string) bool {
	var stack []rune
	flag := true
	for _, i := range []rune(s) {
		if i == '(' || i == '[' || i == '{' {
			stack = append(stack, i)
		} else {
			if len(stack) == 0 {
				return false
			}
			a := stack[len(stack)-1]
			stack = stack[:len(stack)-1]
			if !((a == '(' && i == ')') ||
				(a == '[' && i == ']') ||
				(a == '{' && i == '}')) {
				flag = false
			}
		}
	}
	if len(stack) != 0 {
		flag = false
	}
	return flag
}
